package game.adm.struts.action;

import java.util.List;

import game.adm.controller.BetTypeController;
import game.adm.controller.BonusController;
import game.adm.controller.GameTypeController;
import game.adm.dao.dto.BetTypeDTO;
import game.adm.dao.dto.BonusDTO;
import game.adm.dao.dto.GameTypeDTO;
import game.adm.struts.form.BetTypeForm;
import game.adm.struts.form.BonusForm;
import game.adm.struts.form.GameTypeForm;
import game.web.base.Constants;
import game.web.base.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXSecurityAction;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;
import projectx.web.base.navi.Function;

public class BonusAction extends ProjectXSecurityAction {

	@Override
	protected boolean isPostMethodOnly() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	protected ActionForward execute(User user, Function function,
			ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		UserContext uc = getUc();
		BonusForm bonusForm = (BonusForm) form;
		String operator = bonusForm.getOperator();
		uc.put(Constants.ADM_REQUEST_IP, request.getRemoteAddr());
		

		if ("2".equals(operator) || "5".equals(operator)) {
			GameTypeForm gform = new GameTypeForm();
			gform.setOperator("1");
			GameTypeController.execute(uc, gform);
			
			BetTypeForm bform = new BetTypeForm();
			bform.setOperator("1");
			BetTypeController.execute(uc, bform);
		}
		
		BonusController.execute(uc, (ProjectXForm) form);
		

		if("2".equals(operator) || "5".equals(operator)){
			List<GameTypeDTO> gameTypeList = (List<GameTypeDTO>) getUcAttribute(Constants.ADM_GAMETYPE_LIST);
			request.setAttribute(Constants.ADM_GAMETYPE_LIST, gameTypeList);
			
			List<BetTypeDTO> betTypeList = (List<BetTypeDTO>) getUcAttribute(Constants.ADM_BETTYPE_LIST);
			request.setAttribute(Constants.ADM_BETTYPE_LIST, betTypeList);
			
			List<BonusDTO> rows = (List<BonusDTO>) getUcAttribute(Constants.ADM_BONUS_LIST);
			request.setAttribute(ConstantsProjectX.VIEW_HELPER, rows);
		}else if("3".equals(operator)){
			BonusDTO dto = (BonusDTO) getUcAttribute(Constants.ADM_BONUS_RECORD);
			request.setAttribute(ConstantsProjectX.VIEW_HELPER, dto);
		}
		
		debugEnd();
		return findForward(mapping, forwardSuccess);
	}
}
